#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <pwd.h>
#include <shadow.h>

int check_pass(const char *plainpw, const char *cryptpw)
{
	return (strcmp(crypt(plainpw,cryptpw), cryptpw) == 0);
} 

int main()
{
	char username[20];
	char password[20];
	struct spwd *pwd;

	fprintf(stdout, "Input username:");	
	scanf("%s", username);
	printf("\n");
	fprintf(stdout, "Input password:");
	scanf("%s", password);

	if ((pwd = getspnam(username)) == NULL){
		fprintf(stderr, strerror(errno));
		exit(-1);
	}
	if (check_pass(password, pwd->sp_pwdp))
		printf("\nSuccess!\n");
	else 
		printf("\nFail!\n");
	
	return 0;
}
